moveStroe.service( 'myserver', [ '$rootScope', '$http', 'Upload', function( $rootScope, $http, Upload ){

  /**
   *
   * @param file 文件
   * @param v 类型 图片类型 1，logo 2，图集
   */
  this.imgUpload = function( file, v ){
    $scope = $rootScope
    $scope.fileInfo = file;
    Upload.upload( {
      url: '/admin/upload/imgUpload?type=' + v,
      data: { 'username': $scope.username },
      file: file
    } ).progress( function( evt ){
      var progressPercentage = parseInt( 100.0 * evt.loaded / evt.total );
      // console.log('progess:' + progressPercentage + '%' + evt.config.file.name);
      $scope.$broadcast( 'progessload-img', progressPercentage );
    } ).success( function( data, status, headers, config ){
      //上传成功  发布结果
      $scope.$broadcast( 'images', data );
    } ).error( function( data, status, headers, config ){
      //上传失败
      console.log( 'error status: ' + status );
    } );
  }
  // return {
  //   imgsUpload:imgsUpload
  //      };
} ] );
/**
 * 删除图片
 */
moveStroe.service('delmove',['$rootScope','myAlert',function($rootScope){
     this.remove=function(id){
       $.get('/Admin/images/delImg',{id:id},function(data){
             if(data.status){
               return true;
             }else{
               return false;
             }
       })
     }
}])

/**
 * 表单验证
 */
moveStroe.service( 'fromdata', [ '$rootScope', function( $rootScope ){
  return validate = {
    'require': function( val ){
      if( val == '' || val == null ){
        return false;
      }else{
        return true;
      }
    },
  }
} ] )
/**
 * 弹出框
 */

moveStroe.service( 'myAlert', [ '$rootScope', '$uibModal', '$log', '$document', function( $rootScope, $uibModal, $log, $document ){
  var $ctrl = this;
  $ctrl.animationsEnabled = true;
  $ctrl.open = function( msg, size, parentSelector ){
    var parentElem = parentSelector ? angular.element( $document[ 0 ].querySelector( '.modal-demo ' + parentSelector ) ) : undefined;
    var modalInstance = $uibModal.open( {
      animation: $ctrl.animationsEnabled,
      ariaLabelledBy: 'modal-title',
      ariaDescribedBy: 'modal-body',
      templateUrl: '/Admin/Plug/alert',
      controller: 'ModalInstanceCtrl',
      controllerAs: '$ctrl',
      size: 'sm',
      resolve: {
        data: function(){
          return msg;
        }
      }
    } );
  };
} ] )
/**
 *  内容弹出框
 */
moveStroe.service( 'alertContent', [ '$rootScope', '$uibModal', '$log', '$document', function( $rootScope, $uibModal, $log, $document ){
  var $ctrl = this;
  $ctrl.animationsEnabled = true;
  $ctrl.open = function( data, size, parentSelector ){
    var parentElem = parentSelector ? angular.element( $document[ 0 ].querySelector( '.modal-demo ' + parentSelector ) ) : undefined;
    var modalInstance = $uibModal.open( {
      animation: $ctrl.animationsEnabled,
      ariaLabelledBy: 'modal-title',
      ariaDescribedBy: 'modal-body',
      templateUrl: '/Admin/Plug/alertContent',
      controller: 'ModalInstanceCtrl',
      controllerAs: '$ctrl',
      size: size,
      resolve: {
        data: function(){
          return data;
        }
      }
    } );
  };

  $ctrl.file = function( data, size, parentSelector ){
    var parentElem = parentSelector ? angular.element( $document[ 0 ].querySelector( '.modal-demo ' + parentSelector ) ) : undefined;
    var modalInstance = $uibModal.open( {
      animation: $ctrl.animationsEnabled,
      ariaLabelledBy: 'modal-title',
      ariaDescribedBy: 'modal-body',
      templateUrl: '/Admin/Plug/fileContent',
      controller: 'view_editUploadCtrl',
      controllerAs: '$ctrl',
      size: size,
      resolve: {
        data: function(){
          return data;
        }
      }
    } );
  };

  $ctrl.upload = function( data, size, parentSelector ){
    var parentElem = parentSelector ? angular.element( $document[ 0 ].querySelector( '.modal-demo ' + parentSelector ) ) : undefined;
    var modalInstance = $uibModal.open( {
      animation: $ctrl.animationsEnabled,
      ariaLabelledBy: 'modal-title',
      ariaDescribedBy: 'modal-body',
      templateUrl: '/Admin/Plug/uploadContent',
      controller: 'FileUploadCtrl',
      controllerAs: '$ctrl',
      size: size,
      resolve: {
        data: function(){
          return data;
        }
      }
    } );
  };
  $ctrl.edit = function( data, size, parentSelector ){
    var parentElem = parentSelector ? angular.element( $document[ 0 ].querySelector( '.modal-demo ' + parentSelector ) ) : undefined;
    var modalInstance = $uibModal.open( {
      animation: $ctrl.animationsEnabled,
      ariaLabelledBy: 'modal-title',
      ariaDescribedBy: 'modal-body',
      templateUrl: '/Admin/Plug/editContent',
      controller: 'editUploadCtrl',
      controllerAs: '$ctrl',
      size: size,
      resolve: {
        data: function(){
          return data;
        }
      }
    } );
  };
} ] )
/**
 * 树形
 */
moveStroe.service('tree',['$rootScope',function($rootScope){

  /**
   *
   * @param data 数据
   * @param b 级别深度
   */
  this.arr=[];
    this.tree=function(data,b){
      b=b+1;
      for(i in data){
        if(typeof data[i].pname==undefined){
          return ;
        }else {
          this.arr.push({tree:b,data:data[i]})
          this.tree(data[i].pname,b)
        }
      }
    }
  this.conv=function(data){
    this.arr=[];
    this.tree(data,0)
    return this.arr;
  }
}])
/**
 * 获取菜单
 */

moveStroe.service('menu',function(tree){
  //获取栏目

  this.getCategory=function(){
    var ret='';
    $.get( '/Admin/Category/gets',  function( data ){
      var ret= data.msg.data
      var ret=tree.conv(data.msg)
      for(b in ret){
        ret[b].tree1='';
        for( var i=1;i<ret[b].tree;i++){
          ret[b].tree1+='++';
        }
      }
    } )
    console.log(ret);
    return ret;
  }

})
